#导入tkinter
import tkinter

#创建主窗口
win = tkinter.Tk()

#设置标题
win.title("列表控件")

#设置窗口大小及位置
#win.geometry("200x200+600+200")

#设置变量
biv=tkinter.StringVar()
#创建一个列表框
lb=tkinter.Listbox(win,selectmod=tkinter.EXTENDED,listvariable=biv)

#遍历学生姓名 并且加入列表框
for i in ["张三","李四","王五","赵六","覃七","黄八","福贵","德莱文","牛头","末日","孙悟空","铁男","瞎子","佟大为","van"]:
    lb.insert(tkinter.END,i)
#设置双击的函数a
def listprint(event):
    print(lb.get(lb.curselection())+"早上好！")

#设置双击鼠标左键，会触发的事件
lb.bind("<Double-Button-1>",listprint)

#添加滚动条
scroll=tkinter.Scrollbar(win)
#显示滚动条
scroll.pack(side=tkinter.RIGHT,fill=tkinter.Y)
#显示列表框
lb.pack(side=tkinter.LEFT,fill=tkinter.Y)

#配置滚动条
scroll.config(command=lb.yview)
#配置列表框
lb.config(yscrollcommand=scroll.set)





#进入消息循环
win.mainloop()
